/*****************************************************************************
 * 
 *  File:  sequencer.h
 *  -----
 * 
 *  Copyright Statement:
 *  --------------------
 *  This software is protected by Copyright and the information contained
 *  herein is confidential. The software may not be copied and the information
 *  contained herein may not be used or disclosed except with the written
  *  (C) Hisi. 2004-2005.
 * 
 *  Project:  
 *  --------
 * 
 *  Description:
 *  ------------
 *  This header file contains the sequencer manager definitions 
 * 
 *  Modification History:
 *  ---------------------
 *  Date        Version         Author        		 Details
 *  ----        -------        ------         		-------
 *  Dec.15      1.1           Huang Yonghua       	  Original
 *
 *****************************************************************************/

#ifndef _HI6810_SEQUENCER_INC 
#define _HI6810_SEQUENCER_INC 
#include "uartmgr.h"

/*memory device  MACRO definiton  start */
#define BFLOADERAPP_MAX_MEMDEVICE            8

#define BFLOADERAPP_MEMORY_NOR_FLASH		         0x30
#define BFLOADERAPP_MEMORY_NAND_FLASH            0x40
#define BFLOADERAPP_MEMORY_NAND_FLASH_SP         0x41
#define BFLOADERAPP_MEMORY_NAND_FLASH_LP         0x42
#define BFLOADERAPP_MEMORY_RAM                   0x80
#define BFLOADERAPP_MEMORY_UNKNOWN               0xFF

#define BFLOADER_IBT_ADDRESS                     0x800
#define BFLOADER_IBT_LENGTH                      2048   /* 2048 bytes or 512 words */
/*memory device  MACRO definiton  end */

/*Scenario start */
#define BFLOADERAPP_CMD_BOOT    0x00
#define	BFLOADERAPP_CMD_ERASE   0x01
#define	BFLOADERAPP_CMD_WRITE   0x02
#define	BFLOADERAPP_CMD_EXEC    0x04
#define	BFLOADERAPP_CMD_UPLOAD  0x08
#define	BFLOADERAPP_CMD_CALCSIG	0x10
#define	BFLOADERAPP_CMD_VERIFY	0x20
#define	BFLOADERAPP_CMD_OTP   	0x40
	
//#define BFLOADERAPP_MAX_OTPREG  16
/*Scenario end*/


/*
 * DEFINITIONS
 *****************************************************************************/
#define WM_APP2  0 /*add by H00100243  */


#define BFLOADERAPP_MMITOTHREAD_START   (WM_APP2 + 100)
#define BFLOADERAPP_MMITOTHREAD_STOP    (WM_APP2 + 101)

#define BFLOADERAPP_THREADTOMMI_START   (WM_APP2 + 100)
#define BFLOADERAPP_THREADTOMMI_STOP    (WM_APP2 + 101)
#define BFLOADERAPP_THREADTOMMI_ABORT   (WM_APP2 + 102)
#define BFLOADERAPP_THREADTOMMI_ERROR   (WM_APP2 + 103)
#define BFLOADERAPP_THREADTOMMI_INFO    (WM_APP2 + 104)
#define BFLOADERAPP_THREADTOMMI_PERCENT (WM_APP2 + 105)
#define BFLOADERAPP_THREADTOMMI_DEBUG   (WM_APP2 + 106)
#define BFLOADERAPP_THREADTOMMI_WARNING (WM_APP2 + 107)

/*memory device type definition start */
enum
{
	SCRAM_MEMDEVICE = 0,
	USER_MEMDEVICE,
	DEV0_MEMDEVICE,
	DEV1_MEMDEVICE,
	DEV2_MEMDEVICE,
	DEV3_MEMDEVICE,
	NAND_FLASH,
  	SDI
};

#define LOCAL_NAME_LEN    64
#define MEMORY_IDENTIFIER_LEN  16
typedef struct MemoryDeviceTag
{
	unsigned int	m_unBaseAddress;
	unsigned int	m_unProgTime;
	unsigned int	m_unEraseTime;
	int	          m_nMemoryType;
	char       m_sLocationName[LOCAL_NAME_LEN];
	char	      m_sMemoryIdentifier[MEMORY_IDENTIFIER_LEN];

}MemoryDevice;
/*memory device type definition start  end*/


/*Erase config start */
enum {
	ERASE_ALL = 0,
	ERASE_APPLISIZE,
	ERASE_CUSTOM
};

typedef struct EraseConfigTag
{
	int 			m_nEraseOption;
	unsigned int	m_unEraseOffset;
	unsigned int	m_unEraseLength;
}EraseConfig;
/*Erase config End */


/*Scenario start */
typedef struct ScenarioTag
{ 
	 int		  	 m_nCommandType;
	 unsigned int  m_unJumpDelay;
	// unsigned int  m_aunOtpRegValue[BFLOADERAPP_MAX_OTPREG];
	 EraseConfig  m_tEraseConfig;
}Scenario;
/*Scenario end*/

/*Linkconfig start*/
enum 
{
	DFLT_BR_COMCONFIG = 0,
	USER_BR_COMCONFIG,
	DFLT_LD_COMCONFIG,
	USER_LD_COMCONFIG
};

#define BFLOADERAPP_MAX_COMCONFIG 4
typedef struct  LinkConfigTag  
{
	BFLOADER_COM_CONFIG_T	m_tComConfig;
}LinkConfig;

/*Linkconfig End*/


#define UART_LOADER         1
//#define TARGETNAME_LEN 64

typedef struct TargetConfigTag
{
	unsigned char*		m_sApplicationFile;
	unsigned char*			m_sLoaderFile;
	BOOL			m_bLoaderIsExternal;

	unsigned int	m_unEBIAddress;
	unsigned int	m_unEBIValue;
	int			m_nTargetId;
	int			m_nCurMemDevice;
	int			m_nLoaderMemDevice;
	int 		  	m_nExternalLoaderType;
	
	MemoryDevice m_atMemoryDevice[BFLOADERAPP_MAX_MEMDEVICE];
	LinkConfig	m_atLinkConfig[BFLOADERAPP_MAX_COMCONFIG];
	Scenario 	m_tScenario;

}TargetConfig;
/*target cofig end */


/*sequencer type definiton*/
enum {
	MEMDEVICE_RAM = 0,
	MEMDEVICE_FLASH
};

enum {
	CMD_BOOTROM = 0,
	CMD_LOADER
};

typedef struct SequencerContextTag
{  
	BOOL           m_bSibleyFlash;
	BOOL           m_bCmdTarget;    // BootRom or Loader comand

	BOOL            m_bLoaderConfig;
	BOOL            m_bEraseConfig;
	BOOL 	      m_bTargetConfig;
	BOOL  	      m_bComPortConfig;
	
	unsigned char *m_pucLoaderData;
	unsigned char *m_pucAppliData;

	int            m_nLoaderDataLength;
	int            m_nAppliDataLength;
	int            m_nMemoryDeviceType;

	TargetConfig targetConfig;
	TargetConfig * m_ptTargetConfig;
	BFLOADER_COM_CONFIG_T * m_ptHandleComConfig;
}SequencerContext;

/****************************************************************************
 *
 * Function:          MDM_ImgDownloadInit()
 *
 * Description:	Init  download  , MUST BE CALLED BEFORE ANY OTHER I/F!!
 *
 * Input parameters:  void
 *
 * Return:				void
 *
 *****************************************************************************/
 void MDM_ImgDownloadInit(void);

/****************************************************************************
 *
 * Function:          MDM_LoaderConfig()
 *
 * Description:	Init  download  setting
 *
 * Input parameters:
 *			  bExternalLoader         	External Loader or not
 * 			  pLoaderData			Data source
 *			  loaderLen			Data Length
 *			  un_targetMemDev	Target  Memory 
 *
 * Return:					Error Code
 *
 *****************************************************************************/
unsigned char MDM_LoaderConfig( BOOL b_ldExternal,unsigned char* pu_ldData, unsigned int un_ldLen,unsigned int  un_targetMemDev);
/****************************************************************************
 *
 * Function:          MDM_EraseConfig()
 *
 * Description:	    Set NOR Flash Erase para.
 *
 * Input parameters:  
 *                    bErase    		Erase or not 
 *		         erasOption     	ERASE_ALL / ERASE_APPLISIZE / ERASE_CUSTOM
 *			  eraseOffset      	Erase start address
 *			  eraseLen        	Erase length
 * 
 *
 * Return:					Error Code
 *
 *****************************************************************************/
unsigned char MDM_EraseConfig (BOOL  b_Erase, unsigned int un_ErasOption, unsigned int un_EraseOffset, unsigned int un_EraseLen);

/****************************************************************************
 *
 * Function:          MDM_TargetConfig()
 *
 * Description:	Init  target setting
 *
 * Input parameters:     
 *		         targetType    		Target type, default: TARGET_PNX5230_2A 
 *			  bSecureSupport      	Secure support or not
 *		
 *
 * Return:					Error Code
 *
 *****************************************************************************/
unsigned char MDM_TargetConfig(int n_targetType, BOOL b_SecureSupport);
/****************************************************************************
 *
 * Function:          MDM_ComPortInit()
 *
 * Description:	Init  download  setting
 *
 * Input parameters:  
 *                    nComPort    		 	Port number 
 *		         nBaudRate    		Baud rate setting Target type, default:  
 *			  nDataBit      			Data Bit
 *			  nParity         	      Parity 
 * 			  nStopBit			Stop Bit
 *
 * Return:					Error Code
 *
 *****************************************************************************/
unsigned char MDM_ComPortConfig(int n_ComPort, int n_BaudRate, int n_DataBit, int n_Parity,int n_StopBit);

/****************************************************************************
 *
 * Function:          MDM_ImgDownload()
 *
 * Description:	Init  download  setting
 *
 * Input parameters:                    				 	
 *										
 * 	          pSrc    				Modem image data source
 *			  dataLen      			Data length
 *
 * Return:				Error Code
 *
 *****************************************************************************/
unsigned char  MDM_ImgDownload(unsigned char* pun_Src, unsigned int un_DataLen);

/*****************************************************************************
 *
 * Function:     ut_ModemPowerup()
 *
 * Description:     Modem power up
 *
 * Input parameters: BOOL bPwrup TRUE: power up, else modem power down
 *
 * Output parameters:    BFLOADER_COM_ERROR_CODE_T
 *
 * Return:     int
 *
 *****************************************************************************/
BFLOADER_COM_ERROR_CODE_T  ut_ModemPowerup(BOOL bPwrup);

/*****************************************************************************
 *
 * Function:     ut_ModemReset()
 *
 * Description:     Modem power up
 *
 * Input parameters: BOOL bPwrup TRUE: power up, else modem power down
 *
 * Output parameters:    BFLOADER_COM_ERROR_CODE_T
 *
 * Return:     int
 *
 *****************************************************************************/
BFLOADER_COM_ERROR_CODE_T  ut_ModemReset(BOOL bReset);

/*****************************************************************************
 *
 * Function:     MDM_SEQInit()
 *
 * Description:     Set the target configuration and build the communication with the BR_ROM 
 *
 * Input parameters: unsigned int un_targetMemDev
 *
 * Return:     Error Code
 *
 *****************************************************************************/
unsigned char MDM_SEQInit(unsigned int un_targetMemDev);


#endif/* _HI6810_INCUARTDRV_ */
